﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Comm;

namespace CJGL
{
    public partial class ConfigForm : Form
    {
        public ConfigForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ConfigForm_Load(object sender, EventArgs e)
        {

            List<string> liststr = new List<string>();

            foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
            {
                liststr.Add(printer);
            }

            this.cboprint1.DataSource = liststr;
            cboprint1.SelectedItem = XML.read("cboprint1", "p.xml");
            this.txtscann_ip1.Text = XML.read("scanner_ip1", "p.xml");
            this.txtscann_prot1.Text = XML.read("scanner_port1", "p.xml");
            this.txtscann_ip2.Text = XML.read("scanner_ip2", "p.xml");
            this.txtscann_prot2.Text = XML.read("scanner_port2", "p.xml");
            string ni = XML.read("alert_prot", "p.xml");
            cboAlert_prot.SelectedItem = ni;
            this.txtBaudrate.Text = XML.read("Baudrate", "p.xml");
            txtalertTime1.Text = XML.read("Alter_time1", "p.xml");
            txtalertTime2.Text = XML.read("Alter_time2", "p.xml");
            txtalertTime3.Text = XML.read("Alter_time3", "p.xml");
            txtTCYS1.Text = XML.read("TCYS1", "p.xml");
            txtTCYS2.Text = XML.read("TCYS2", "p.xml");
            txtSCYS.Text = XML.read("SCYS", "p.xml");
            //延时多久停止输送线
            txtYCTZ.Text = XML.read("YCTZ", "p.xml");
            txtPrintCount.Text = XML.read("PrintCount", "p.xml");
            txtZTBC.Text = XML.read("ZTBC", "p.xml");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            XML.write("scanner_ip1", txtscann_ip1.Text, "p.xml");
            XML.write("scanner_port1", txtscann_prot1.Text, "p.xml");
            XML.write("scanner_ip2", txtscann_ip2.Text, "p.xml");
            XML.write("scanner_port2", txtscann_prot2.Text, "p.xml");
            XML.write("alert_prot", cboAlert_prot.SelectedItem.ToString(), "p.xml");
            XML.write("Baudrate", txtBaudrate.Text, "p.xml");
            XML.write("Alter_time1", txtalertTime1.Text, "p.xml");
            XML.write("Alter_time2", txtalertTime2.Text, "p.xml");
            XML.write("Alter_time3", txtalertTime3.Text, "p.xml");
            XML.write("TCYS1", txtTCYS1.Text, "p.xml");
            XML.write("TCYS2", txtTCYS2.Text, "p.xml");
           
            XML.write("cboprint1", cboprint1.SelectedItem.ToString(), "p.xml");
            XML.write("PrintCount", txtPrintCount.Text, "p.xml");
            XML.write("SCYS", txtSCYS.Text, "p.xml");
            XML.write("YCTZ", txtYCTZ.Text, "p.xml");
            XML.write("ZTBC", txtZTBC.Text, "p.xml");

            //赋值文件配置
            ClsParmart.scanner_ip1 = txtscann_ip1.Text;
            ClsParmart.scanner_port1 = txtscann_prot1.Text;
            ClsParmart.scanner_ip2 = txtscann_ip2.Text;
            ClsParmart.scanner_port2 = txtscann_prot2.Text;
            ClsParmart.alert_prot = cboAlert_prot.SelectedItem.ToString();
            ClsParmart.Baudrate = txtBaudrate.Text;
            ClsParmart.Alter_time1 = txtalertTime1.Text;
            ClsParmart.Alter_time2 = txtalertTime2.Text;
            ClsParmart.Alter_time3 = txtalertTime3.Text;
            ClsParmart.SCYS = txtSCYS.Text;
            ClsParmart.YCTZ = txtYCTZ.Text;
            ClsParmart.ZTBC = txtZTBC.Text;
            ClsParmart.TCYS1 = txtTCYS1.Text;
            ClsParmart.TCYS2 = txtTCYS2.Text;
            ClsParmart.cboprint1 = cboprint1.SelectedItem.ToString();
            try
            {
                int count = Convert.ToInt32(txtPrintCount.Text);
            }catch (Exception ex)
            {
                MessageBox.Show("打印张数请输入数字类型！！");
                return;
            }
            ClsParmart.PrintCount = txtPrintCount.Text;
            MessageBox.Show("保存成功");
            this.Close();
        }

        private void txtscann_prot2_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
